package day20170424.homework;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;

import org.junit.Test;

public class HomeWork05 {
	/**
	 *	5: 使用BufferedWriter  把 "中深软通123" 写入曹io1704 BufferedWriter.txt 
	 * @throws Exception
	 */
	@Test
	public void homework05(){
		//定义一个字符输出流
		Writer writer = null;
		//定义一个字符缓存流
		BufferedWriter bw = null;
		try {
			//获取到类路径
			File file = new File("txt/BufferedWriter.txt");
			String str = "中深软通123啊啊啊";
			//将路径装入字符输出流
			writer = new FileWriter(file);
			//将输出流装入字符缓存流
			bw = new BufferedWriter(writer);
			//写入一行
			bw.write(str);
			bw.flush();
		} catch (IOException e) {
			e.printStackTrace();
		}finally {
			if(null != bw){
				try {
					bw.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if(null != writer){
				try {
					writer.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
}
